/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package csse3004.GD;

import java.util.ArrayList;

/**
 *
 * @author Tom McNair - S41758984
 * @author David Bullock 42062222
 */
public class MCQuestion extends Question {
    
    private String style = null;
    private boolean template = false;
    private boolean ranking = false;
    private String demographic = null;
    /**
     * the id of the question it is comparing to. -1 means not set
     */
    private int comparison = -1;
    private ArrayList<MCAnswer> answers = new ArrayList<MCAnswer>();

    public MCQuestion(ArrayList<MCAnswer> answers) {
        super.setMC();
        this.answers = answers;
    }

    public MCQuestion() {
        super.setMC();
    }    

    /**
     * returns the ID of the question to  be compared against
     * @return ID of the question it's compared to
     */
    public int getComparison() {
        return comparison;
    }

    /**
     * sets the question to the compared against
     * @param comparison the question to be compared to
     */
    public void setComparison(int comparison) {
        this.comparison = comparison;
    }

    /**
     * if this returns something other than null, then this question is a demograhpic question
     * @return type of demographic this question sets
     */
    public String getDemographic() {
        return demographic;
    }

    /**
     * sets the demographic to be compared to
     */
    public void setDemographic(String demographic) {
        this.demographic = demographic;
    }

    public boolean isRanking() {
        return ranking;
    }

    public void setRanking(boolean ranking) {
        this.ranking = ranking;
    }

    public String getStyle() {
        return style;
    }

    public void setStyle(String style) {
        this.style = style;
    }

    public boolean isTemplate() {
        return template;
    }

    public void setTemplate(boolean template) {
        this.template = template;
    }

    /**
     * Automatically generate the HTML for displaying either type of question.
     * Primarily designed for the viewing poll pages
     * 0 = Master, 1= Web
     * @return the HTML that can be shoved directly into the window
     */
    public String displayQuestion(int user) {
        //this was made because David hates the stupid JSTL and so wanted to do 
        //all the logic here
        String html = "";
//        logger.info(getAnswers().size());
        if (user == 0) {
            for (int i = 0; i < getAnswers().size(); i++) {
                html += "<p>";
                html += i + ". " + getAnswers().get(i).getText() + "</p>";
                //TODO David have variable start thing maybe? (ie. a. b. c. Or 1. 2. 3...)
            }
        } else if (user == 1) {
            for (int i = 0; i < getAnswers().size(); i++) {
                html += "<p>";
                html += i + ". " + getAnswers().get(i).getText() + "</p>";
            }
        }
         
        return html;
    }

    public ArrayList<MCAnswer> getAnswers( ) {
        return answers;
    }

    /**
     * Sets the answers related to this question
     * requires id to be set
     * @param Answer List of answers to set (and overwrite the existing set answers)
     * @return true if success, false if ID isn't set (unsuccessful)
     */
    public boolean setAnswers(ArrayList<MCAnswer> Answers) {
        if (id == null) {
            return false;
        }
        for (MCAnswer a : Answers) {
            a.setId(id);
        }
        this.answers = Answers;
        return true;
    }

    public boolean addAnswer(MCAnswer Answer) {
        if (id == null) {
            return false;
        }
        Answer.setId(id);
        this.answers.add(Answer);
        return true;
    }
}
